/*
 * Copyright (C) 2013 rdrrlabs gmail com,
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.rdrrlabs.example.timer2app.core;

import com.rdrrlabs.example.liblabs.app.Bus;

import android.content.Context;

//-----------------------------------------------

/** A singleton using shared structures of the app.
 * <p/>
 * This singleton must NEVER store an object that directly or indirectly holds
 * an Android context such as an activity or a fragment.
 * */
public class GlobalContext {

    private static GlobalContext sContext = new GlobalContext();

    // TODO change override during test
    private final Bus mBus = new Bus();
    private final PrefsStorage mPrefsStorage = new PrefsStorage("prefs");
    private final GAEHelper mGAEHelper = GAEHelper.getInstance();
    private boolean mAppStartDone;

    private GlobalContext() {
    }

    public static GlobalContext getContext() {
        return sContext;
    }

    public PrefsStorage getPrefsStorage() {
        return mPrefsStorage;
    }

    public GAEHelper getGAEHelper() {
        return mGAEHelper;
    }

    public Bus getBus() {
        return mBus;
    }

    /** Initialize a few things once. */
    public void onAppStart(Context androidContext) {
        if (!mAppStartDone) {
            mAppStartDone = true;

            // Reads the pref storage async, since eventually we'll need it.
            mPrefsStorage.beginReadAsync(androidContext);
        }
    }

}


